from os import access
import joblib
from sklearn.model_selection import train_test_split as splitter
from sklearn.neural_network import MLPClassifier
import json

model = joblib.load("SimpleClassifier.pkl")

with open('val.csv','r',encoding='gbk') as file:
    raw_lines=file.readlines()
    file.close()

print(len(raw_lines))


data_val = []
target_val = []
for line in raw_lines:
    str_temp = line.strip("\n").split(",")
    target_val.append(str_temp[-1])
    temp = []
    for item in str_temp[0:-1]:
        temp.append(int(item)/255)

    data_val.append(temp)

pre_result=list(model.predict(data_val)) 

with open('./ocr-exercise/val.json','r',encoding='UTF-8') as f:
    chara_json=json.load(f)
    f.close

val_result={}
count=0
for x in chara_json:
    num=len(chara_json[x])
    str_result=''
    for i in range(num):
        str_result+=str(pre_result[count])
        count+=1
    val_result[x]=str_result

with open("181250116.json","w",encoding = 'utf-8') as file:
    json.dump(val_result,file,ensure_ascii=False,indent=4)